/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Mapper;

import java.sql.*;

/**
 *
 * @author Quang Thao
 */
public class OtherMapper extends DBMapper {

    public OtherMapper() throws SQLException, Exception {
        super();
    }

    public Bean.OtherBean GetInfo(String id) throws Exception {
        PreparedStatement stmt = getConnection().prepareStatement("Select * From Other Where ID='" + id + "'");
        ResultSet rs = stmt.executeQuery();
        Bean.OtherBean other = new Bean.OtherBean();
        if (rs != null && rs.next()) {
            other.setID(id);
            other.setTitle(rs.getString(2));
            other.setContent(rs.getString(3));
        }
        stmt.close();
        return other;
    }

    public int Update(Bean.OtherBean other) throws Exception {
        PreparedStatement stmt = getConnection().prepareStatement("Update Other Set Title='"
                + other.getTitle() + "',Contents='" + other.getContent()
                + "' Where ID='" + other.getID() + "'");
        int kq = stmt.executeUpdate();
        if (kq == 0) {
            stmt = getConnection().prepareStatement("Insert Into Other Values('"
                    + other.getID() + "','" + other.getTitle()
                    + "','" + other.getContent() + "')");
            kq = stmt.executeUpdate();
        }
        stmt.close();
        return kq;
    }
}
